package vaccine.appointment.system.appointmentrecord.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 预约状态枚举类
 */
@Getter
@AllArgsConstructor
public enum AppointmentStatusEnum {
    /**
     * 预约状态
     */
    CANCELLED(-1, "已取消"),
    EXPIRED(0, "已逾期"),
    APPOINTED(1, "待接种"),
    COMPLETED(2, "已接种");

    private final int code;
    private final String description;

    /**
     * 根据名称获取枚举对象
     * @param name 名称
     * @return 枚举对象
     */
    public static AppointmentStatusEnum forName(String name) {
        for(AppointmentStatusEnum appointmentStatusEnum : AppointmentStatusEnum.values()) {
            if(appointmentStatusEnum.name().equalsIgnoreCase(name)) {
                return appointmentStatusEnum;
            }
        }
        return null;
    }

    /**
     * 根据code获取描述
     * @param code 状态码
     * @return 描述
     */
    public static String getDescByCode(Integer code) {
        if (code == null) {
            return "";
        }
        for(AppointmentStatusEnum status : AppointmentStatusEnum.values()) {
            if(status.getCode() == code) {
                return status.getDescription();
            }
        }
        return "";
    }
}
